<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-projectVersion-edit" th:object="${projectVersion}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<input name="productVersionId"  type="hidden" id="treeId" th:field="*{productVersionId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属项目：</label>
				<div class="col-sm-8">
					<select id="projectId" name="projectId" class="form-control m-b">
						<option th:each="project:${projects}" th:value="${project.id}" th:text="${project.name}" th:disabled="${project.status == '1'}" th:selected="${projectVersion.projectId==project.id}"></option>
					</select>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">所属项目：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="projectId" name="projectId" th:field="*{projectId}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">	
				<label class="col-sm-3 control-label">版本号：</label>
				<div class="col-sm-8">
					<input id="version" name="version" th:field="*{version}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否公开：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="${projectVersion.isPublic == '1' ? true : false}" class="onoffswitch-checkbox" id="isPublic" name="isPublic">
						<label class="onoffswitch-label" for="isPublic">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">是否公开：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="isPublic" name="isPublic" th:field="*{isPublic}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">	
				<label class="col-sm-3 control-label">版本名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" th:field="*{name}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">版本状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="${projectVersion.status == '0' ? true : false}" class="onoffswitch-checkbox" id="status" name="status">
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">项目状态：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="status" name="status" th:field="*{status}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">所属产品版本：</label>
				<div class="col-sm-8">
					<span class="label label-success" id = "productName" th:text="*{productVersion.productName}" style="display: inline-block;margin-bottom: 3px">productName</span>
					<input class="form-control" type="text" name="version" onclick="selectProductVersionTree()" readonly="true" id="treeName" th:field="*{productVersion.version}">
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">此版本关联的产品版本：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="productVersionId" name="productVersionId" th:field="*{productVersionId}" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "project/projectVersion"
		$("#form-projectVersion-edit").validate({
            rules:{
                projectId:{
                    required:true,
                },
                version:{
                    required:true,
                },
                isPublic:{
                    required:true,
                },
                status:{
                    required:true,
                },
                productVersion:{
                    required:true,
                },
            }
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            edit();
	            // $.operate.save(prefix + "/edit", $('#form-projectVersion-edit').serialize());
	        }
	    }
        function edit() {
            var id = $("input[name='id']").val();
            var productVersionId = $("input[name='productVersionId']").val();
            var projectId = $("#projectId").val();
            var version = $("input[name='version']").val();
            var name = $("input[name='name']").val();
            var isPublic = $("input[name='isPublic']").is(':checked') == true ? 1 : 0;
            var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "project/projectVersion/edit",
                data : {
                    "id":id,
                    "productVersionId": productVersionId,
                    "projectId": projectId,
                    "version": version,
                    "name": name,
                    "isPublic": isPublic,
                    "status": status,
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
        }

        /*项目版本-新增-选择产品版本树*/
        function selectProductVersionTree() {
            var url = ctx + "system/productVersion/selectProductVersionTree";
            var options = {
                title: '选择产品版本',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                $("#productName").text(body.find('#productName').val()).show().css({"display": "inline-block","margin-bottom": "3px"});
                layer.close(index);
            }
        }
	</script>
</body>
</html>
